<template>
    <div>
        <div class="crumbs">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item>
                    <div class="contentsize">事务查询</div>
                </el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <div class="container">
            <div class="handle-box">
                <el-form ref="form" :model="form" label-width="auto" :inline="true" size="mini">
                    <el-form-item label="档案编号:">
                        <div style="width: 150px">
                            <el-input v-model="form.dabh" placeholder="请输入档案编号"
                                @keyup.enter.native="onSearch"></el-input>
                        </div>
                    </el-form-item>
                    <el-form-item label="房屋地址:">
                        <div style="width: 150px">
                            <el-input v-model="form.dz" placeholder="请输入房屋地址" @keyup.enter.native="onSearch"></el-input>
                        </div>
                    </el-form-item>
                    <el-form-item label="所属事务:">
                        <div style="width: 150px">
                            <el-select v-model="form.processcode" placeholder="请选择所属事务" @change="onSearch" clearable>
                                <el-option v-for="item in ssswlist" :key="item.code" :label="item.name"
                                    :value="item.code"> </el-option>
                            </el-select>
                        </div>
                    </el-form-item>
                    <el-form-item label="是否完结:">
                        <div style="width: 150px">
                            <el-select v-model="form.zt" placeholder="请选择是否完结" @change="onSearch" clearable>
                                <el-option v-for="item in ztlist" :key="item.code" :label="item.name"
                                    :value="item.code"> </el-option>
                            </el-select>
                        </div>
                    </el-form-item>
                    <el-form-item>
                        <el-button type="primary" @click="onSearch" icon="el-icon-search"
                            class="searchcolor">查询</el-button>
                        <el-button @click="reSearch" icon="el-icon-refresh" class="searchcolor">重置</el-button>
                        <el-button type="primary" @click="downloadlist" icon="el-icon-download"
                            class="searchcolor">导出</el-button>
                    </el-form-item>
                </el-form>
            </div>
            <!-- max-height="330" -->
            <el-table :data="tableData" style="width: 100%" :header-cell-style="tableHeaderColor"
                :row-style="tablerowColor" :row-class-name="tableRowClassName" :cell-style="tablecellColor" border
                :max-height="maxHeight">
                <el-table-column prop="dabh" label="档案编号" align="center" width="200" :show-overflow-tooltip="true">
                </el-table-column>
                <el-table-column prop="dz" label="地址" align="center" width="200" :show-overflow-tooltip="true">
                </el-table-column>
                <el-table-column prop="addusername" label="发起人" align="center"> </el-table-column>
                <el-table-column prop="create_time" label="录入日期" align="center">
                    <template slot-scope="scope">
                        {{ scope.row.create_time ? scope.row.create_time.split(' ')[0] : '' }}
                    </template>
                </el-table-column>
                <el-table-column prop="sssw" label="所属事务" align="center"> </el-table-column>
                <el-table-column prop="bjsy" label="办件事由" align="center" :show-overflow-tooltip="true" width="200"> </el-table-column>
                <el-table-column prop="zt" label="是否办结" align="center" width="80">
                    <template slot-scope="scope">
                        {{ scope.row.zt == 0 ? '否' : '是' }}
                    </template>
                </el-table-column>
                <el-table-column label="操作" width="140" align="center">
                    <template slot-scope="scope">
                        <el-button type="text" size="small"
                            @click="gotofwjg(scope.row.processcode, scope.row.id, 'swcx')">详情</el-button>
                        <el-button type="text" size="small"
                            @click="gotoedit(scope.row.processcode, scope.row.id, 'swcx')" v-if="role == '11111' || role == '22222'">编辑</el-button>
                        <el-button type="text" size="small" @click="deleteClick(scope.row)" style="color: red"
                            v-if="role == '11111' || role == '22222'">删除</el-button>
                    </template>
                </el-table-column>
            </el-table> <!-- <el-button type="text" size="small"
                            @click="gotoedit(scope.row.processcode, scope.row.id)">编辑</el-button> -->
            <div class="pagination" style="float: right">
                <el-pagination background layout="total,prev, pager, next,jumper" :total="total"
                    :current-page.sync="current" :page-size="pageSize" @current-change="handleCurrentChange">
                </el-pagination>
            </div>
        </div>
    </div>
</template>

<script>
import { swcxcaselist, csdbnodelete, exportcaselist } from '@/api/index';
import valueList from '@/components/common/valueList.vue';
export default {
    name: 'swcxlist',
    data() {
        return {
            ssswlist: valueList.ssswlist, //所属事物列表
            total: 0,
            current: 1,
            pageSize: 10,
            form: {
                adduser: '', // 发起人ID ,
                addusername: '', // 发起人姓名 ,
                create_name: '', // 创建人 ,
                create_name_id: '', // 创建人id ,
                create_time: '', // 创建时间 ,
                current: 1, // 第几页 ,
                dabh: '', // 档案编号 ,
                dz: '', // 地址 ,
                id: '', // id ,
                pageSize: 10, // 每页数量 ,
                processcode: '', // 流程模板编码(例：fwjg) ,
                rqa: '', // 日期起始 ,
                rqb: '', // 日期结束 ,
                sssw: '', // 所属事务名称 ,
                status_code: '1', // 1正常 2删除 ,
                update_name: '', // 修改人 ,
                update_name_id: '', // 修改人id ,
                update_time: '', // 修改时间 ,
                zt: null, // 是否办结 0：否 1：是
                lcfl: '1'
            },
            tableData: [],
            ztlist: [
                { name: '是', code: 1 },
                { name: '否', code: 0 }
            ],
            maxHeight: null,
            role: this.$store.getters.role
        };
    },
    components: {},
    computed: {},
    methods: {
        // 列表样式
        tableHeaderColor({ row, column, rowIndex, columnIndex }) {
            if (rowIndex === 0) {
                return 'background:linear-gradient(to bottom, #008A94,#0ae2f2)!important;color:#ffffff;font-size:14px;';
            }
        },
        tablerowColor({ row, rowIndex }) {
            return 'height: 42px;font-size:14px;color:black';
        },
        tablecellColor() {
            return 'font-weight:700;color:#000000;border-color:#c0c0c0';
        },
        tableRowClassName({ row, rowIndex }) {
            if (rowIndex % 2 != 0) {
                return 'success-row'; //这是类名
            } else {
                return '';
            }
        },
        // 换页
        handleCurrentChange(val) {
            this.current = val;
            this.form.current = val;
            this.swcxcaselist(this.form);
            console.log(val);
        },
        // 搜索
        onSearch() {
            this.current = 1;
            this.form.current = 1;
            this.swcxcaselist(this.form);
            console.log('搜索');
        },
        // 重置
        reSearch() {
            this.current = 1;
            this.form = {
                adduser: '', // 发起人ID ,
                addusername: '', // 发起人姓名 ,
                create_name: '', // 创建人 ,
                create_name_id: '', // 创建人id ,
                create_time: '', // 创建时间 ,
                current: 1, // 第几页 ,
                dabh: '', // 档案编号 ,
                dz: '', // 地址 ,
                id: '', // id ,
                pageSize: 10, // 每页数量 ,
                processcode: '', // 流程模板编码(例：fwjg) ,
                rqa: '', // 日期起始 ,
                rqb: '', // 日期结束 ,
                sssw: '', // 所属事务名称 ,
                status_code: '1', // 1正常 2删除 ,
                update_name: '', // 修改人 ,
                update_name_id: '', // 修改人id ,
                update_time: '', // 修改时间 ,
                zt: null // 是否办结 0：否 1：是
            };
            this.swcxcaselist(this.form);
            console.log('搜索');
        },
        // 项目列表
        swcxcaselist(data) {
            swcxcaselist(data).then((res) => {
                if (res.code == 200) {
                    this.tableData = res.data.records;
                    this.total = res.data.total;
                } else {
                    this.tableData = [];
                    this.total = 0;
                }
            });
        },
        // 删除
        deleteClick(e) {
            console.log(e);
            this.$confirm('确定删除此条信息吗？')
                .then(() => {
                    let data = { id: e.id };
                    csdbnodelete(data).then((res) => {
                        if (res.code == 200) {
                            this.swcxcaselist(this.form);
                            this.$message.success('删除成功');
                        }
                    });
                })
                .catch(() => {
                    this.$message.success('删除取消');
                });
        },
        // 跳转流程页面
        gotofwjg(val, id, e) {
            if (val == 'jlbqtht1' || val == 'jlbqtht2') {
                this.$router.push({
                    // name: val,
                    name: 'qthtend',
                    params: {
                        id: id
                    }
                });
            } else {
                let firstThree = val.substring(0, 3); // 获取前三个字符
                let rest = val.substring(3); // 获取剩余的字符
                let name = firstThree == 'jlb' ? rest + 'end' : val + 'end';
                // let name = val + 'end';
                this.$router.push({
                    name: name,
                    params: { id: id, num: '1', val: e }
                });
            }
        },
        //跳转编辑页面
        gotoedit(val, id, e) {
            if (val == 'jlbqtht1' || val == 'jlbqtht2') {
                this.$router.push({
                    // name: val,
                    name: 'qthtbj',
                    params: {
                        id: id
                    }
                });
            }else {
                let firstThree = val.substring(0, 3); // 获取前三个字符
                let rest = val.substring(3); // 获取剩余的字符
                let name = firstThree == 'jlb' ? rest + 'bj' : val + 'bj';
                this.$router.push({
                    name: name,
                    params: { id: id, num: '1', val: e }
                });
            }
        },
        // 导出
        downloadlist() {
            exportcaselist(this.form).then((res) => {
                console.log(res);
                const link = document.createElement('a');
                let blob = new Blob([res], {
                    type: 'application/vnd.ms-excel'
                });
                link.style.display = 'none';
                //设置连接
                link.href = URL.createObjectURL(blob);
                link.download = '事务导出文件';
                document.body.appendChild(link);
                //模拟点击事件
                link.click();
                console.log(res);
            });
        }
    },
    mounted() {
        this.$nextTick(() => {
            // window.innerHeight 浏览器窗口的可见高度，下面的 420 是除了table最大高度的剩余空间。
            this.maxHeight = window.innerHeight - 360;
        });
        console.log(this.$store.getters);
        this.swcxcaselist(this.form);
        console.log(valueList);
    }
};
</script>

<style scoped>
.container {
    /* height: calc(100vh - 260px); */
    overflow: hidden;
}

.crumbs {
    background-color: #fff;
    padding: 20px 20px;
}

.indexTitle {
    margin-bottom: 20px;
}

.contentsize {
    font-size: 18px;
    font-weight: 700;
}

.handle-box {
    overflow: hidden;
}

/* 新增按钮 */
.addcolor {
    margin-bottom: 10px;
}

.unloadTitle {
    text-align: left;
    padding-bottom: 10px;
    box-sizing: border-box;
    color: #606266;
}
</style>
<style>
.success-row {
    background-color: #eaf3fb !important;
}
</style>
